package com.xpchenfrank.test;

/**
 * @author xpchen
 * @time 2019\2\21 0021 18:02
 * @Description
 * @copyright Wuxi Yazuo ,Ltd.copyright 2015-2025
 */
public class Switch {

    public static void main(String[] args) {

        String[] strArray = {"on", "off", "on", "off", "off", "off", "on"};
        System.out.println(turnOnTest(strArray));

        System.out.println(turnOnTestAdvanced(strArray));

    }

    public static int turnOnTestAdvanced(String[] strArray) {
        int arrayLength = strArray.length;
        int modVal = arrayLength % 2;
        if(modVal == 1) {
            return (arrayLength / 2);
        } else {
            return (arrayLength / 2) + 1;
        }
    }

    public static int turnOnTest(String[] strArray) {

        for (int i=0; i<strArray.length; i++) {
            strArray[i] = "on";
        }

        showArray(strArray);

        for (int i=0; i<strArray.length; i++) {
            if(i % 2 == 1) {
                strArray[i] = "off";
            }
        }

        showArray(strArray);

        int count = 0;
        for (int i=0; i<strArray.length; i++) {
            String ele = strArray[i];
            if("on".equals(ele)) {
                strArray[i] = "off";
            } else {
                strArray[i] = "on";
                count++;
            }
        }

        showArray(strArray);

        return count;
    }

    public static void showArray(String[] array) {
        for (String s : array) {
            System.out.println("array is " + s);
        }
        System.out.println("-----------------------");
    }
}
